//
//  Invocation.cpp
//  Simulation
//
//  Created by Christopher Kemsley on 2/28/12.
//  Copyright (c) 2012 iAppolopolis. All rights reserved.
//



template <typename TargetType>
ObjectInvocation<TargetType> :: ObjectInvocation	( TargetType * inTarget , CallbackMethod inMethod )
:	Invocation	()
,	mTarget		( inTarget )
,	mMethod		( inMethod )
	{
	if ( inTarget==0 )
		throw Exception ( "ObjectInvocation" , "Target was nil in constructor" , __FILE__,__LINE__ ) ;
	if ( inMethod==0 )
		throw Exception ( "ObjectInvocation" , "Method was nil in constructor" , __FILE__,__LINE__ ) ;
	}




template <typename TargetType>
void		ObjectInvocation<TargetType> :: invoke () const
	{
	(mTarget->*mMethod) (  ) ;
	}



template <typename TargetType>
Invocation*	ObjectInvocation<TargetType> :: create	( TargetType * inTarget , CallbackMethod inMethod )
	{
	return new ObjectInvocation<TargetType> ( inTarget , inMethod ) ;
	}
template <typename TargetType>
Invocation*	ObjectInvocation<TargetType> :: invocation	( TargetType * inTarget , CallbackMethod inMethod )
	{
	Invocation* i = new ObjectInvocation<TargetType> ( inTarget , inMethod ) ;
	i -> autorelease() ;
	return i ;
	}





template <typename TargetType,typename ContextType>
ObjectContextInvocation<TargetType,ContextType> :: ObjectContextInvocation	( TargetType * inTarget , CallbackMethod inMethod , ContextType const & incontext )
:	Invocation	()
,	mTarget		( inTarget )
,	mContext	( incontext )
,	mMethod		( inMethod )
	{
	if ( inTarget==0 )
		throw Exception ( "ObjectInvocation" , "Target was nil in constructor" , __FILE__,__LINE__ ) ;
	if ( inMethod==0 )
		throw Exception ( "ObjectInvocation" , "Method was nil in constructor" , __FILE__,__LINE__ ) ;
	}




template <typename TargetType,typename ContextType>
void		ObjectContextInvocation<TargetType,ContextType> :: invoke () const
	{
	(mTarget->*mMethod) ( mContext ) ;
	}



template <typename TargetType,typename ContextType>
Invocation*	ObjectContextInvocation<TargetType,ContextType> :: create	( TargetType * inTarget , CallbackMethod inMethod , ContextType const & inContext )
	{
	return new ObjectContextInvocation<TargetType,ContextType> ( inTarget , inMethod , inContext ) ;
	}
template <typename TargetType,typename ContextType>
Invocation*	ObjectContextInvocation<TargetType,ContextType> :: invocation	( TargetType * inTarget , CallbackMethod inMethod , ContextType const & inContext )
	{
	Invocation* i = new ObjectContextInvocation<TargetType,ContextType> ( inTarget , inMethod , inContext ) ;
	i -> autorelease() ;
	return i ;
	}
